{__NOLAYOUT__}
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    <meta name="Keywords" content="">
    <meta name="Description" content="">
    <meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" type="text/css" href="/agent/css/product_list.css"/>
    <link rel="stylesheet" type="text/css" href="/agent/css/my_dingdan.css"/>
    <link rel="stylesheet" type="text/css" href="/agent/css/public.css"/>
    <script type="text/javascript" src="/agent/js/jquery-2.1.0.js" ></script>
    <script type="text/javascript" src="/agent/js/rem.js" ></script>
    <script type="text/javascript" src="/agent/js/jquery.more.js" ></script>
    <script type="text/javascript" src="/agent/js/mescroll.min.js" ></script>
    <link rel="stylesheet" type="text/css" href="/agent/css/mescroll.min.css"/>
    <title>订单</title>
</head>
<body class="body_tj" style="background-color: #F5F5F5;">
<div class="goods_nav hid" id="menu">
    <div class="Triangle"><h2></h2></div>
</div>
<div id="tbh5v0">
	<div style="overflow: hidden;">
    <ul class="order_listtop">
        <li class="{if isset($whereStatus.deliverystatus) || isset($whereStatus.pay) }  {else}  on {/if}"><a href='/agent/agent/order'>全部({$total})</a></li>
        <li class='{if isset($whereStatus.deliverystatus)} {$whereStatus.deliverystatus == 0 ? "on" :""} {/if}'><a href='/agent/agent/order?filter={"deliverystatus":"0","pay":1}&op="{}"'>待发货({$status.daifahuo})</a></li>
        <li class='{if isset($whereStatus.deliverystatus)} {$whereStatus.deliverystatus == 1 ? "on" :""} {/if}'><a href='/agent/agent/order?filter={"deliverystatus":"1"}&op="{}"'>待收货({$status.daishouhuo})</a></li>
        <li class='{if isset($whereStatus.deliverystatus)} {$whereStatus.deliverystatus == 3 ? "on" :""} {/if}'><a href='/agent/agent/order?filter={"deliverystatus":"3"}&op="{}"'>已完成({$status.yiwancheng})</a></li>
    </ul>
    </div>
    <script>
      $(function(){
        $('.order_listtop li').click(function(){
          var i = $(this).index();
          $(this).addClass('on').siblings().removeClass('on');
        });
        var myHeight = $(window).height();
		$('.container').css('height',myHeight+'px');

      });
    </script>
    <div class="container">
		<div id="mescroll" class="my-address mescroll">
			<div id="addressList" class="address-list">
		        <div id="J_ItemList" class="order">
		             <div class="success">
	                    <img style="accelerator: 100%" src="/agent/img/kong.png"/>
	                </div>
	                <p class="welcome">目前还没有订单</p>
		        </div>
			</div>
		</div>
	</div>
</body>
<script>
var offset = 0; //页码
var limit = 10;  //每页数据固定条数
var param = window.location.search;
//创建MeScroll对象
var mescroll = new MeScroll("mescroll", {
    up: {
        callback: upCallback //上拉加载的回调
        ,
        empty: {
            //列表第一页无任何数据时,显示的空提示布局; 需配置warpId或clearEmptyId才生效;
            warpId:'mescroll', //父布局的id; 如果此项有值,将不使用clearEmptyId的值;
            icon: null, //图标,默认null
            tip: "暂无新的数据~", //提示
            btntext: "", //按钮,默认""
            btnClick: null, //点击按钮的回调,默认null
        },
    }
});
//上拉加载的回调 page = {num:1, size:5}; num:当前页 默认从1开始, size:每页数据条数,默认5
function upCallback(page) {
    $.ajax({
        url: '/agent/agent/order'+param+'&offset='+offset+'&limit='+limit,
        dataType:'json',
        type:'GET',
        success: function(json) {
            offset += limit++;
            limit = 10;
            $('#addressList').append(render(json));
            mescroll.endByPage(json.rows.length, json.total);
        },
        error: function(e) {
            //联网失败的回调,隐藏下拉刷新和上拉加载的状态
            mescroll.endErr();
        }
    });
}

function render(data)
{
  var html = '';
  $.each(data.rows,function (index,val) {
     html +='<ul class="single_item info""> \n' +
       '   <div class="order_list"> \n' +
       '    <h2> <span>订货单号：'+val.nb+'</span> <strong>'+val.deliverystatus_text+'</strong> </h2> \n';
        $.each(val.order_item,function (i,v) {
          html +='     <div class="order_list_goods"> \n' +
            '      <dl> \n' +
            '       <dt> \n' +
            '        <img src="'+v.preproductimg_text+'" /> \n' +
            '       </dt> \n' +
            '       <dd class="name"> \n' +
            '        <strong>'+v.preproductname_text+'</strong> \n' +
            '       </dd> \n' +
            '       <dd class="pice"> '+v.unit_price +
            '        <em>x'+v.num+'</em>\n' +
            '       </dd> \n' +
            '      </dl> \n' +
            '     </div>\n' ;
        });
  html +='    <div class="pic">\n' +
       '     共'+val.order_item.length+'件商品&nbsp;&nbsp;合计：\n' +
       '     <strong>'+val.order_price+'</strong>\n' +
       '    </div> \n' +
       '<div class="anniu" style="width:95%;"> \n' ;
    if(val.deliverystatus >= 1)
    {
      html +='<a class="wl "href="#" onclick="wuliu($(this));">查看物流</a>  \n' ;
    }
    if(val.deliverystatus == 1 && val.pay == 1)
    {
        html +='<a class="wl "href="#" onclick="queren('+val.id+');">确认收货</a> \n';
    }
    if( val.status == -1)
    {
      html +='<a href="/agent/shopping/checkOrder/id/'+val.id+'">前往提交</a> \n' ;
    }
    if(val.pay == 3 && val.status == -1 || val.pay == 4)
    {
      //html +='<a href="/agent/shopping/checkOrder/id/'+val.id+'">前往支付</a> \n' ;
    }else{
      html+='     <span>'+val.status_text+'</span> \n' ;
     // html+='     <span>'+val.pay_text+'</span> \n' ;
    }
   html+='    </div><p class="wl_info" style="padding: 0.3rem;background: #fff;font-size: 0.22rem;line-height: 0.36rem;display: none;">'+val.express_info+'</p> \n' +
       '   </div> \n' +
       '  </ul> ';
  });
  $('.success,.welcome').css('display','none');
  return html;
}

function wuliu(val) {
  val.parent().next().toggle();
}
function queren(val) {
  $.ajax({
    url: '/agent/agent/deliverystatus/ids/'+val,
    dataType:'json',
    type:'GET',
    success: function(json) {
      // if(json.status == 0)
      // {
      //   window.location.reload();
      //   return false
      // }
      window.location.reload();
    },
    error: function(e) {
      //联网失败的回调,隐藏下拉刷新和上拉加载的状态
    }
  });

}
</script>
</html>